package com.lsa.letcode.the112.pathSum;

import com.lsa.letcode.common.TreeNode;

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public boolean hasPathSum(TreeNode root, int sum) {
        if (root == null){
        	return false;
        }
        else {
        	int curSum = sum - root.val;
        	if (root.left == null && root.right == null && curSum == 0){
        		return true;
        	}
        	return hasPathSum(root.left, curSum) || hasPathSum(root.right, curSum); 
        }
    }
}